package com.lottery.ruok.lottrey.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.applozic.mobicomkit.ChatConfig;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.chat.model.prize.message.PrizeMessage;
import com.lottery.ruok.lottrey.userInfo.UserInfo;
import com.lottery.ruok.lottrey.utils.TimeUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;
import glideHelp.GlideHelper;
import io.rong.imlib.model.Message;
import ui.NavigateBar;
import utils.StringUtils;

/*
* 打赏详情
* */

public class GiveRewardDetailActivity extends BaseActivity {

    public static final String EXTRA_PRIZE_MESSAGE = "extra_prize_message";
    @BindView(R.id.money)
    TextView money;
    @BindView(R.id.avatar)
    CircleImageView avatar;
    @BindView(R.id.from)
    TextView from;
    @BindView(R.id.to_avatar)
    CircleImageView toAvatar;
    @BindView(R.id.to)
    TextView to;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.navigateBar)
    NavigateBar navigateBar;
    private PrizeMessage prizeMessage;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_give_reward_detail);
        ButterKnife.bind(this);
        init();
        initView();
    }

    private void init() {
        Intent intent = getIntent();
        if (intent != null) {
            prizeMessage = intent.getParcelableExtra(EXTRA_PRIZE_MESSAGE);
        }
    }

    private void initView() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// HH:mm:ss
        if (!prizeMessage.getDate().equals("")) {
            Date date = new Date(Long.valueOf(prizeMessage.getDate()));
            // time.setText(StringUtils.formatTime(simpleDateFormat.format(date), "yyyy-MM-dd HH:mm:ss"));
            time.setText(simpleDateFormat.format(date));
        } else {
            time.setVisibility(View.INVISIBLE);
        }

        from.setText(prizeMessage.getSendUserNickname());
        to.setText(prizeMessage.getReceiveUserNickname());
        money.setText(prizeMessage.getMoney() + "");
        GlideHelper.loadImage(GiveRewardDetailActivity.this,prizeMessage.getSendUserAvatar() , avatar);
        GlideHelper.loadImage(GiveRewardDetailActivity.this,prizeMessage.getReceiveUserAvatar() , toAvatar);
        if(!UserInfo.getToken().equals("")){
            if (UserInfo.getUsername().equals(prizeMessage.getReceiveUserNickname()) || UserInfo.getUsername().equals(prizeMessage.getSendUserNickname())) {
                navigateBar.setOperateTitle("打赏记录");
                navigateBar.setOnOperateClickListener(new NavigateBar.OnOperateClickListener() {
                    @Override
                    public void onOperateClick(View view) {
                        Intent intent = new Intent(GiveRewardDetailActivity.this, MyRedPacketActivity.class);
                        intent.putExtra("isThreeTab", true);
                        startActivity(intent);
                    }
                });
            }
        }
    }

    public static void startActivity(Context context, PrizeMessage content) {
        Intent intent = new Intent(context, GiveRewardDetailActivity.class);
        intent.putExtra(EXTRA_PRIZE_MESSAGE, content);
        context.startActivity(intent);
    }
}
